package com.bawei.demo_shoppingcar.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bawei.demo_shoppingcar.R;

import static android.R.id.list;

/**
 * Created by HP on 2017/3/15.
 */

public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private final LayoutInflater inflate;
    private Context context;
    public RecyclerAdapter(Context context){
        this.context=context;
        inflate = LayoutInflater.from(context);

    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view=null;
        if(i==1){
            view = this.inflate.inflate(R.layout.my_recy_item, viewGroup, false);
        }else if(i==2){
            view = this.inflate.inflate(R.layout.my_recy_item_one, viewGroup, false);
        }
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {

    }

    @Override
    public int getItemViewType(int position) {
        if(position%2 == 0){
            return 1;
        } else if(position%2==1){
            return 2;
        } else {
            return super.getItemViewType(position);
        }
    }
    @Override
    public int getItemCount() {
        return 100;
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        public MyViewHolder(View itemView) {
            super(itemView);
            RecyclerView my_item_recyclerView= (RecyclerView) itemView.findViewById(R.id.my_item_recyclerView);
            LinearLayoutManager linearLayoutManager=new LinearLayoutManager(context);
            linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
            my_item_recyclerView.setLayoutManager(linearLayoutManager);
            my_item_recyclerView.setAdapter(new MyRecyclerAdapter(context));

        }
    }
    class MyViewHolderOne extends RecyclerView.ViewHolder{
        public MyViewHolderOne(View itemView) {
            super(itemView);
            RecyclerView my_item_recyclerView= (RecyclerView) itemView.findViewById(R.id.my_item_recyclerView);
            LinearLayoutManager linearLayoutManager=new LinearLayoutManager(context);
            linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
            my_item_recyclerView.setLayoutManager(linearLayoutManager);

        }
    }

}
